package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.PvFileScoreEntity;
import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.IDQYCFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.util.DataUtil;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DQYCFileScoreServiceImpl implements IDQYCFileScoreService {
    @Autowired
    private IFileScoreService fileScoreService;
    @Autowired
    private FileScoreMapper fileScoreMapper;
    @Override
    public WindFileScoreEntity FDDQYCFileScore(WindFileScoreEntity windFileScoreEntity) {

        String plantId = windFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = windFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "DQYC";
        String plantType = "FD";
        String tableName = "HISDB.NW_NE_FILE_DATACHECK_FD_DQYC";

        //上送文件数量
        int DQYCNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float DQYCFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float DQYCRate = 0;
        //文件上送率
        float DQYCSendRate = 0;
        //文件得分
        float DQYCScore = 0;
        //文件合格率
        float DQYCQualifiedRate = 0;


        if (DQYCNum > 0) {
            //文件上送率
            DQYCSendRate = 100;
            DQYCRate = (float) DQYCNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            DQYCScore = fileDataScore;
            //文件合格率
            DQYCQualifiedRate = DQYCScore / DQYCFullScore * 100;
        }else {
            DQYCRate=0;
            DQYCScore=0;
            DQYCSendRate=0;
            DQYCQualifiedRate= 0;
        }
        windFileScoreEntity.setDQYCNum(DQYCNum);
        windFileScoreEntity.setDQYCRate(DQYCRate);
        windFileScoreEntity.setDQYCScore(DQYCScore);
        windFileScoreEntity.setDQYCFullScore(DQYCFullScore);
        windFileScoreEntity.setDQYCSendRate(DQYCSendRate);
        windFileScoreEntity.setDQYCQualifiedRate(DQYCQualifiedRate);

        return windFileScoreEntity;
    }

    @Override
    public PvFileScoreEntity GFDQYCFileScore(PvFileScoreEntity pvFileScoreEntity) {
        String plantId = pvFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = pvFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "DQYC";
        String plantType = "GF";
        String tableName="HISDB.NW_NE_FILE_DATACHECK_GF_DQYC";

        //上送文件数量
        int DQYCNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float DQYCFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float DQYCRate = 0;
        //文件上送率
        float DQYCSendRate = 0;
        //文件得分
        float DQYCScore = 0;
        //文件合格率
        float DQYCQualifiedRate = 0;

        if (DQYCNum > 0) {
            //文件上送率
            DQYCSendRate = 100;
            DQYCRate = (float) DQYCNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            DQYCScore = fileDataScore;
            //文件合格率
            DQYCQualifiedRate = DQYCScore / DQYCFullScore * 100;
        }else {
            DQYCRate=0;
            DQYCScore=0;
            DQYCSendRate=0;
            DQYCQualifiedRate= 0;
        }
        pvFileScoreEntity.setDQYCNum(DQYCNum);
        pvFileScoreEntity.setDQYCRate(DQYCRate);
        pvFileScoreEntity.setDQYCScore(DQYCScore);
        pvFileScoreEntity.setDQYCFullScore(DQYCFullScore);
        pvFileScoreEntity.setDQYCQualifiedRate(DQYCSendRate);
        pvFileScoreEntity.setDQYCSendRate(DQYCQualifiedRate);

        return pvFileScoreEntity;
    }

}
